/*
 * @Timur Suleimanov, Kiev 2012
 * Neighbouring numbers
 * Finding two neighbouring numbers in an array with the
 * smallest distance to each other.
 */
import java.util.Scanner;

public class NeighbouringNumbers {

    public static int getFirstElementInMinimumDistance(int[] numbers) {
        int index = 0;
        for (int i = 1; i < numbers.length - 1; i++) {
            if (Math.abs(numbers[index] - numbers[index + 1])
                    > Math.abs(numbers[i] - numbers[i + 1])) {
                index = i;
            }
        }
        return index;
    }

    public static void main(String[] args) {
        int setOfNumbers[] = new int[7];
        Scanner in = new Scanner(System.in);
        System.out.println("Please enter 7 numbers ");
        for (int i = 0; i < setOfNumbers.length; i++) {
            setOfNumbers[i] = in.nextInt();
        }
		System.out.printf("First index of an element %d is %d\n",
						   setOfNumbers[getFirstElementInMinimumDistance(setOfNumbers)],
						   getFirstElementInMinimumDistance(setOfNumbers));
        in.close();
    }
}
